<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>axios 创建对象发送请求</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>
</head>
<body>
    <!-- http://api.xiaohigh.com -->
    <button>王者荣耀</button>
    <button>英雄联盟</button>
    <hr>
    <!-- http://127.0.0.1:3000 -->
    <button>电影</button>
    <button>图书</button>

    <script>
      // axios.defaults.baseURL = 'http://api.xiaohigh.com'

      // 当一个前端项目需要请求多个后台服务的接口时, 必须使用create()
      // 实际项目: 都会用create
      // create方法返回是一个函数
    const newAxios1 = axios.create({
        baseURL: 'http://api.xiaohigh.com'
    })
    const newAxios2 = axios.create({
        baseURL: 'http://localhost:3000'
    })

    const btns = document.querySelectorAll('button');
    btns[0].onclick = async() => {
        const str1 = await newAxios1('/heros')
        console.log(str1)
    }
    btns[1].onclick = () => {
        newAxios1('/lol')
    }
    btns[2].onclick = () => {
        newAxios2('/movie')
    }
    btns[3].onclick = () => {
        newAxios2('/book')
    }
    

    </script>
</body>
</html>